# Contributor: Guy Godfroy <guy.godfroy@gugod.fr>
# Maintainer: Guy Godfroy <guy.godfroy@gugod.fr>
pkgname=dmarc-metrics-exporter
pkgver=1.1.0
pkgrel=0
pkgdesc="Prometheus metrics exporter from DMARC reports"
url="https://github.com/jgosmann/dmarc-metrics-exporter"
# s390x: because of py3-xsdata
#        see https://gitlab.alpinelinux.org/alpine/aports/-/issues/15642
arch="noarch !s390x"
license="MIT"
depends="
	py3-bite-parser
	py3-dataclasses-serialization
	py3-prometheus-client
	py3-structlog
	py3-uvloop
	py3-xsdata
	uvicorn
	"
makedepends="
	py3-gpep517
	py3-installer
	py3-poetry-core
	py3-poetry-dynamic-versioning
	py3-wheel
	"
checkdepends="
	py3-aiohttp
	py3-pytest-aiohttp
	py3-pytest-asyncio
	py3-pytest-forked
	py3-requests
	"
install="$pkgname.pre-install"
subpackages="$pkgname-pyc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/jgosmann/dmarc-metrics-exporter/archive/refs/tags/v$pkgver.tar.gz
	dmarc-metrics-exporter.initd
	dmarc-metrics-exporter.confd
	"

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	# need a specific running imap server
	pytest --forked \
		--deselect=dmarc_metrics_exporter/tests/test_imap_queue.py \
		--deselect=dmarc_metrics_exporter/tests/test_imap_client.py \
		--deselect=dmarc_metrics_exporter/tests/test_e2e.py::test_successful_processing_of_incoming_queue_message
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
	rm -r "$pkgdir"/usr/lib/python*/site-packages/dmarc_metrics_exporter/tests/

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
551139cf7d18131e45e8b86b5f41555350b60c72bd230f458c96af4522be701b8f309840f6ad98ad98ff4db38fe9cf173c636c401f7e65f4430e5913c0f7a1f3  dmarc-metrics-exporter-1.1.0.tar.gz
a067d586708eed0501687d0117ad7cbf8acb4624b161daa99a39e8fb116d2f6265fa7000425f21139c6033b88da5915f5adef7584b0708b5d190343c387cc1a5  dmarc-metrics-exporter.initd
b5c8ef2683b8d4a0cb6b886a8acdd5e7b8e361320cdb7256f9e29960b44cad590b1a98b65cad23de22e72c33519fcb9c971b92892683ab1692e060fb0772b0df  dmarc-metrics-exporter.confd
"
